﻿
using System;
using System.Collections.Generic;
using UnityEngine;

namespace Yoozoo.Gameplay.City
{
    /// <summary>
    /// 挂载在交互物下，用于调整位置、缩放
    /// </summary>
    /// 
    public class CityRealMoveGoodsMono : MonoBehaviour
    {

        [Serializable]
        public class PointData
        {
#if UNITY_EDITOR
            [Header("备注")]
            [NonSerialized]
            public string Text;
#endif
            
            public int PosOffsetId;
            public Vector3 NpcNodePosition;
            public Vector3 NpcNodeRotate;
        }
        
        public Vector3 RoomNodePosition;
        public Vector3 RoomNodeRotate;

        public List<PointData> NpcNodePoint;

        public void ChangeNodeRotate(bool roomOrNpc, int posOffsetId = -1)
        {
            if (roomOrNpc)
            {
                transform.localPosition = RoomNodePosition;
                transform.localEulerAngles = RoomNodeRotate;
            }
            else
            {
                if (NpcNodePoint == null || NpcNodePoint.Count == 0)
                {
                    return;
                }

                var pointData = NpcNodePoint[0];
                for (int i = 0; i < NpcNodePoint.Count; i++)
                {
                    var tempPointData = NpcNodePoint[i];
                    if (tempPointData.PosOffsetId == posOffsetId)
                    {
                        pointData = tempPointData;
                        break;
                    }
                }
                
                transform.localPosition = pointData.NpcNodePosition;
                transform.localEulerAngles = pointData.NpcNodeRotate;
            }
        }
    }
}
